<?php
	require '../conn.php';
	$username = trim($_REQUEST['username']);
	$password = trim($_REQUEST['password']);
	$email = trim($_REQUEST['email']);
	$telephone = trim($_REQUEST['telephone']);
	$nickname = trim($_REQUEST['nickname']);
	
	if ($username =="" || $password=="" || $email=="" || $telephone=="" || $nickname=="")
	{
		echo "{\"error\":1,\"message\":\"注册信息不完整\"}";
		exit;
	}
	
	$checkQuery = "SELECT * FROM user WHERE username=".$username;
	$checkResult = mysql_query($checkQuery);
	
	if ($myrow = mysql_fetch_row($checkResult)) {
		echo "{\"error\":1,\"message\":\"该账户已经注册过了\"}";
		exit;
	}
	
	$checkQuery = "SELECT * FROM user WHERE nickname=".$nickname;
	$checkResult = mysql_query($checkQuery);
	
	if ($myrow = mysql_fetch_row($checkResult)) {
		echo "{\"error\":1,\"message\":\"该昵称已经存在了\"}";
		exit;
	}
	
	$createtime = time();
	$query = "INSERT INTO user(username, password, email, telephone, nickname, type, createtime)"
						."VALUES('$username','$password','$email','$telephone','$nickname','normal','$createtime')";
						
	$result = mysql_query($query);
	$rowid = mysql_insert_id();
	if ($rowid > 0) {
		echo "{\"success\":0,\"message\":\"注册成功\"}";
	}
	else {
		echo "{\"error\":1,\"message\":\"注册失败\"}";
	}
			
?>